package com.zone.domain.acticity.model.entity;

import com.zone.domain.acticity.model.valobj.ActivityStateEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * @author: zongzi
 * @description: 抽奖活动
 * @date: 2024/6/23
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ActivityEntity {
    /** 活动ID */
    private Long activityId;
    /** 活动名称 */
    private String activityName;
    /** 活动描述 */
    private String activityDesc;
    /** 开始时间 */
    private Date beginDateTime;
    /** 结束时间 */
    private Date endDateTime;
    /** 抽奖策略ID */
    private Long strategyId;
    /** 活动状态 */
    private String state;

    /**
     * 校验活动是否有效
     */
    public EffectResult takeEffect() {
        boolean effect = true;
        String errorMsg = null;
        if (!ActivityStateEnum.OPEN.getCode().equals(this.getState())) {
            effect = false;
            errorMsg = String.format("活动【%s】还未开启", this.getActivityName());
        }
        Date currentDate = new Date();
        if (!(currentDate.after(this.getBeginDateTime()) && currentDate.before(this.getEndDateTime()))) {
            effect = false;
            errorMsg = String.format("活动【%s】开启时间为（%s - %s）", this.getActivityName(), this.getBeginDateTime(), this.getEndDateTime());
        }
        return EffectResult.builder()
                .effect(effect)
                .errorMsg(errorMsg)
                .build();
    }

    // 校验结果
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class EffectResult {
        private boolean effect;
        private String errorMsg;
    }
}
